<template>
  <div class="login_contauner">
      <div class="login_box">
        <!-- 表单区域 -->
        <el-form ref="loginFormRef" :model='loginForm' :rules='loginFormRules' class="login_form">
          <!-- 用户名 -->
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" prefix-icon="iconfont icon-user" ></el-input>
          </el-form-item>
          <!-- 密码 -->
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" type='password' prefix-icon="iconfont icon-3702mima" ></el-input>
          </el-form-item>
          <el-form-item class="btn">
            <el-button type="primary" @click='login'>登录</el-button>
          </el-form-item>
        </el-form>
        <!-- 按钮区域 -->
      </div>
  </div>
</template>
<script>

export default {
  data () {
    return {
      // 表单数据绑定
      loginForm: {
        username: '',
        password: ''
      },
      // 表单输入验证
      loginFormRules: {
        // 用户名输入验证
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        // 密码输入验证
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created () {

  },
  methods: {
    // 点击重置表单
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    // 点击验证表单
    login() {
      this.$refs.loginFormRef.validate(async valid => {
        if (!valid) return
        console.log(this.loginForm)
        const { data: res } = await this.$http.post('/login', {body: {username: 'admin,null', password: '123456'}})
        console.log(res);
        // if (res.meta.status !== 200) return this.$message.error('登录失败！')
        
        this.$message.success('登陆成功')
        // 将登陆成功后的token保存到客户端
        window.sessionStorage.setItem('token', res.body.token)
        // 跳转到后台页面路由地址 /home
        this.$router.push('/customerResourceAllocateNBList')
      })
    }
  }
}
</script>

<style>
.login_contauner {
    background-color: #2b4b6b;
    height: 100%;
}
.login_box {
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%)
}
.avatar_box{
  width: 115px;
  height: 115px;
  padding: 10px;
  border: 1px solid #eee;
  border-radius: 50%;
  box-shadow: 0 0 10px #ddd;
  position: absolute;
  left:50%;
  transform:translate(-50%,-50%);
  background-color: #fff;
  img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #eee;
  }

}
.login_form{
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box
}
.btn{
  display: flex;
  justify-content: flex-end;
}
</style>